Web push service

Introduction#

The Web Push Service is a core component of the SuperSet Telegram Notification Bot that enables real-time browser notifications through the Web Push protocol with VAPID (Voluntary Application Server Identification) authentication. This service integrates smoothly with the multi-channel notification ecosystem alongside Telegram notifications, providing users with instant updates delivered directly to their web browsers.

The service implements a detailed notification delivery mechanism that includes subscription management, payload formatting, VAPID encryption, and reliable error handling for delivery failures. It operates as part of a larger system that monitors multiple data sources (SuperSet portal, email notifications, official websites) and distributes notifications through various channels to registered users.

Project structure#

The Web Push Service is organized within the application’s modular architecture, following service-oriented design principles with clear separation of concerns:

Core components#

The Web Push Service consists of several interconnected components that work together to provide reliable browser notification delivery:

WebPushService class#

The primary service class that implements the INotificationChannel protocol, handling all aspects of web push notification delivery including VAPID authentication, subscription management, and payload formatting.

VAPID authentication system#

Implements Voluntary Application Server Identification for secure push notification delivery, requiring cryptographic keys and contact email for authentication with push providers.

Subscription management#

Manages user subscriptions through the database service, storing subscription endpoints and cryptographic keys associated with each user’s browser installations.

Notification delivery pipeline#

Processes notification requests through a structured pipeline that formats payloads, applies VAPID signatures, and handles delivery failures with automatic cleanup of invalid subscriptions.

Architecture overview#

The Web Push Service operates within a detailed notification architecture that supports multiple delivery channels:

The architecture ensures smooth integration between web browsers and the notification system, with automatic handling of subscription lifecycle management and delivery failures.

Detailed component analysis#

VAPID encryption implementation#

The Web Push Service implements VAPID (Voluntary Application Server Identification) encryption for secure notification delivery:

The VAPID implementation includes:

  • Private Key Management: Cryptographic key for signing push requests
  • Public Key Distribution: Shared with web clients for subscription verification
  • Claims Generation: Creation of authentication claims with contact email
  • Signature Validation: Verification of push provider authentication

Browser subscription management#

The service manages browser subscriptions through a structured lifecycle:

Subscription management includes:

  • Registration: Storing subscription endpoints and cryptographic keys
  • Validation: Periodic verification of subscription validity
  • Cleanup: Automatic removal of expired or invalid subscriptions
  • Persistence: Database storage of subscription data linked to user profiles

Push notification delivery mechanisms#

The notification delivery pipeline follows a standardized process:

Integration with multi-channel notification ecosystem#

The Web Push Service integrates with the broader notification ecosystem:

Dependency analysis#

The Web Push Service relies on several key dependencies for secure and reliable operation:

The dependency graph reveals a sophisticated stack designed for production reliability:

  • pywebpush: Core library for Web Push protocol implementation
  • py-vapid: VAPID signature generation and validation
  • cryptography: Underlying cryptographic operations
  • http-ece: HTTP Encrypted Content Encoding for payload encryption
  • FastAPI/uvicorn: Modern asynchronous web framework for API endpoints

Performance considerations#

The Web Push Service is designed with several performance optimizations:

Asynchronous processing#

  • Non-blocking Operations: Webhook server uses FastAPI with async capabilities
  • Connection Pooling: Efficient database connections through PyMongo
  • Batch Processing: Multiple subscriptions processed in parallel where safe

Resource management#

  • Lazy Loading: Optional dependency loading prevents runtime errors
  • Memory Efficiency: Payload truncation and streaming where applicable
  • Connection Reuse: Database connections maintained throughout service lifetime

Scalability features#

  • Graceful Degradation: Service continues operating even without VAPID keys
  • Error Isolation: Individual subscription failures don’t impact others
  • Automatic Cleanup: Invalid subscriptions removed to prevent performance degradation

Troubleshooting guide#

Common VAPID configuration issues#

Problem: Web push notifications not working despite proper setup Solution: Verify VAPID key configuration and provider compatibility

Problem: Subscription registration failing with HTTP 501 Solution: Check VAPID key availability and service initialization

Problem: Delivery failures with 404/410 responses Solution: Automatic cleanup removes invalid subscriptions; verify subscription validity

Subscription management issues#

Problem: Subscriptions not persisting in database Solution: Verify database connectivity and user ID mapping

Problem: Duplicate subscriptions accumulating Solution: Implement subscription deduplication logic in database service

Performance issues#

Problem: Slow notification delivery Solution: Monitor database query performance and optimize subscription retrieval

Problem: Memory leaks during high-volume delivery Solution: Implement proper resource cleanup and connection pooling

Conclusion#

The Web Push Service represents a reliable implementation of browser notification delivery within the SuperSet Telegram Notification Bot ecosystem. Its architecture demonstrates best practices in service-oriented design, security implementation, and scalability considerations.

The service successfully bridges the gap between traditional Telegram notifications and modern web browser capabilities, providing users with flexible notification delivery options. The VAPID implementation ensures secure communication with push providers, while the subscription management system maintains clean, valid subscription lists.

Key strengths of the implementation include:

  • Security: Detailed VAPID encryption and authentication
  • Reliability: Graceful degradation and automatic error recovery
  • Scalability: Efficient batch processing and resource management
  • Integration: Smooth coordination with the broader notification ecosystem

Future enhancements could include WebSocket support for real-time bidirectional communication, expanded browser compatibility testing, and advanced analytics for delivery performance monitoring.

Appendices#

Configuration requirements#

The Web Push Service requires specific environment variables for proper operation:

Variable Description Required Example
VAPID_PRIVATE_KEY Private key for VAPID authentication Yes -----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----
VAPID_PUBLIC_KEY Public key distributed to clients Yes BO4...
VAPID_EMAIL Contact email for VAPID Yes [email protected]

API endpoints#

The webhook server exposes several endpoints for web push functionality:

Endpoint Method Description
/api/push/subscribe POST Register new push subscription
/api/push/unsubscribe POST Remove existing subscription
/api/push/vapid-key GET Retrieve VAPID public key
/api/notify/web-push POST Send notification via web push only

Browser compatibility#

The service supports major modern browsers with Web Push API support:

  • Chrome: Version 50+
  • Firefox: Version 44+
  • Safari: Version 11.3+
  • Edge: Version 79+